package com.example.mybatis_puls.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Created with IntelliJ IDEA.
 * ClassName: UserConfig
 * Package: com.example.mybatis_puls.config
 * Description:
 * User: fzykd
 *
 * @Author: LQH
 * Date: 2023-01-14
 * Time: 20:58
 */
@Configuration

@MapperScan("com.example.mybatis_puls.mapper")  //也可以在每个Mapper中添加@Mapper注解  (可以加载启动类上 有了配置类 最好加载配置类上)
public class MyBatisPlusConfig {

    //配置插件 配置的分页插件
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor(){
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        //添加分页插件
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        //添加乐观锁插件
        interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
        return interceptor;
    }


}
